<template>
  <div>
    <el-form-item label="选择表单">
      <el-input v-model="initObject" readonly placeholder="请选择表单" @focus="handleUserIconClick" />
    </el-form-item>
    <SelectDialog title="选择表单" :append-to-body="true" :show="userSelDialogFormVisible" @on-ok="selectUserOk" @on-cancel="selectUserCancel">
      <workflowForm ref="usersTable" :for-selection="true" :multiple-selected="true" />
    </SelectDialog>
  </div>
</template>
<script>
import workflowForm from '@neu/dcom-ui/views/workOrder/definition/tables'
import SelectDialog from '@neu/biz-core/components/SelectDialog'
export default {
  name: 'WorkflowFormCom',
  components: {
    workflowForm,
    SelectDialog
  },
  props: {
    initWorkflowForm: {
      required: false,
      type: String,
      default: null
    }
  },
  data() {
    return {
      userSelDialogFormVisible: false,
      initObject: this.initWorkflowForm
    }
  },
  created() {
  },
  methods: {
    /** 选择用户按钮 */
    handleUserIconClick() {
      this.userSelDialogFormVisible = true
    },
    selectUserOk() {
      var users = this.$refs.usersTable.selections
      if (users.length > 1) {
        return this.$Message({
          showClose: true,
          message: '只允许选择1个表单',
          type: 'error'
        })
      }
      if (users.length < 1) {
        this.initObject = null
      } else {
        this.initObject = users[0].code
      }

      this.userSelDialogFormVisible = false
      this.emitData()
    },
    selectUserCancel() {
      this.userSelDialogFormVisible = false
    },
    /** 删除某一项 */
    removeUser(tag) {
      this.initObject = null
      this.emitData()
    },
    emitData() {
      this.$emit('selectForm', this.initObject)
    }
  }
}
</script>
